package com.ibeetl.cms.util;

import com.ibeetl.admin.core.web.JsonResult;
import com.ibeetl.cms.entity.Sincerity;
import com.ibeetl.cms.entity.StateTable;
import java.util.Date;
import java.util.List;

public class common {
//    /**
//     * 退回
//     * @param rolename
//     * @param state
//     */
//    public static void retreat(String rolename,StateTable state){
//        if (rolename==null || rolename=="") {
//            rolename="shouli";
//        }
//        if (rolename.equals("chushen")) {
//            state.setProcessResult(ProcessConstant.FIRSTCHECK_STR);
//            state.setBusinessState(ProcessConstant.FIRSTCHECK_STR);
//            state.setBusinessStateCode(ProcessConstant.FIRSTCHECK);
//        } else if (rolename.equals("fushen")) {
//            state.setProcessResult(ProcessConstant.FINALCHECK_BACK_STR);
//            state.setBusinessState(ProcessConstant.FINALCHECK_BACK_STR);
//            state.setBusinessStateCode(ProcessConstant.FINALCHECK_BACK);
//        } else if(rolename.equals("shouli")){//受理
//            state.setProcessResult(ProcessConstant.COMPANY_BACK_STR);
//            state.setBusinessState(ProcessConstant.COMPANY_BACK_STR);
//            state.setBusinessStateCode(ProcessConstant.COMPANY_BACK);
//        }
//    }
//
//    /**
//     * 通过
//     * @param rolename
//     * @param state
//     */
//    public static void adopt(String rolename,StateTable state){
//        if (rolename==null || rolename=="") {
//            rolename="shouli";
//        }
//        if (rolename.equals("chushen")) {
//            state.setProcessResult(ProcessConstant.FIRSTCHECK_ADOPT_STR);
//            state.setBusinessState(ProcessConstant.TO_FINALCHECK_STR);
//            state.setBusinessStateCode(ProcessConstant.TO_FINALCHECK);
//        } else if (rolename.equals("fushen")) {
//            state.setProcessResult(ProcessConstant.FINALCHECK_ADOPT_STR);
//            state.setBusinessState(ProcessConstant.DONE_STR);
//            state.setBusinessStateCode(ProcessConstant.DONE);
//        } else if(rolename.equals("shouli")){//受理
//            state.setProcessResult(ProcessConstant.COMPANY_ADOPT_STR);
//            state.setBusinessState(ProcessConstant.TO_FIRSTCHECK_STR);
//            state.setBusinessStateCode(ProcessConstant.TO_FIRSTCHECK);
//        }
//    }

    /**
     * 判断是保存还是保存并申请
     * @param state
     * @param judge
     */
    public  static void common(StateTable state, String judge) {
        if(judge.equals("add")){
            state.setBusinessState(ProcessConstant.WAIT_APPLICATION_STR);
            state.setBusinessStateCode(ProcessConstant.WAIT_APPLICATION);
        }else if(judge.equals("declare")) {
            state.setDate(new Date());
            state.setBusinessState(ProcessConstant.TO_COMPANY_STR);
            state.setBusinessStateCode(ProcessConstant.TO_COMPANY);
        }
    }

    //诚信判断
    public static  boolean  judge(String roleName, String businessType, List<Sincerity> list,Integer companyId) {//判断是否是诚信黑名单
        if (roleName.equals(RoleConstant.PERSON)) {
            for (int i = 0; i < list.size(); i++) {
                if (list.get(i).getBusinessType().indexOf(businessType)>=0 && list.get(i).getType().equals("个人"))
                    return false;
                else if (list.get(i).getTypeId().equals(companyId) && list.get(i).getType().equals("企业") &&
                        list.get(i).getBusinessType().indexOf(businessType)>=0) return false;
            }return true;
        } else if (roleName.equals(RoleConstant.COMPANY)) {
            for (int i = 0; i < list.size(); i++) {
                if (list.get(i).getBusinessType().indexOf(businessType)>=0 && list.get(i).getType().equals("企业"))
                    return false;
            }return true;
        }else return true;
    }
    }